// async function fn() {
//   return 100;// 异步函数
// }

// (async () => {
//   const a = fn();// 一个promise
//   const b = await fn();// 100
//   console.log(a, b);
// })();// 包裹函数



// (async () => {
//   console.log('start');
//   const a = await 100;
//   console.log('a',a);
//   const b = await Promise.resolve(200);
//   console.log('b',b);
//   const c = await  Promise.reject(300);
//   console.log('c',c)
//   console.log('end')
// })(); // start a 100 b 200 c 报错 后面不打印



// ! promise和setTimeout和async/await
async function async1(){
  console.log('asynce1 start');// 2
  await async2();
  console.log('async1 end');// 6
}

async function async2(){
  console.log('async2')// 3
}
console.log('script start')// 1

setTimeout(function (){
  console.log('setTimeout')// 8
},0)

async1();

new Promise(resolve=>{
  console.log('promise1');// 4 因为async1方法的await堵塞了 但是还是会先把后面的同步的代码先执行了,再到async1 end 再到后面的promise2
  resolve();
}).then(()=>{
  console.log('promise2');// 7
})
console.log('script end')// 5
// script start 
// asynce1 start
// async2
// asynce1 end
// promise1
// script end
// promise2
// setTimeout
